const {BrowserWindow} = require('electron')
const isDev = require('electron-is-dev')
const path = require('path')

let win;

function create() {

    //创建窗口, 默认设置为隐藏
    win = new BrowserWindow({
        width: 600,
        height: 300,
        webPreferences: {
            nodeIntegration: true
        },
        show: false
    })

    //显示窗口
    win.on('ready-to-show', () => {
        win.show()
    })

    //环境判断
    if (isDev){
        win.loadFile(path.resolve(__dirname, '../../renderer/pages/main/index.html'))
    }
}

function show() {
    if (win.isMinimizable()){
        win.resize()
    }else {
        win.show()
    }
}

function close(){
    win.close()
}


module.exports = {create, show, close}
